package Test03;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UDPLoginClient {
	public static void main(String[] args) {
		DatagramSocket socket=null;
		try {
			String info="你好，我想咨询你一个问题";
			InetAddress ia=InetAddress.getByName("localhost");
			byte[] bytes = info.getBytes();
			DatagramPacket dp = new DatagramPacket(bytes, bytes.length, ia, 5000);
			socket=new DatagramSocket();
			socket.send(dp);
			
			byte[] replys=new byte[1024];
			DatagramPacket dp1=new DatagramPacket(replys,replys.length);
			socket.receive(dp1);
			String str=new String(dp1.getData(), 0,dp1.getData().length);
			System.out.println("服务器端的响应是:"+str);
		} catch (Exception e) {
			// TODO: handle exception
		}finally {
			socket.close();	
		}
	}
	

}
